import { createRouter, createWebHistory } from 'vue-router'
import Voice from '../views/Voice.vue'
import Room from '../views/Room.vue'
import Social from '../views/Social.vue'
import Statistics from '../views/Statistics.vue'
import Training from '../views/Training.vue'
import Test from '../views/Test.vue'
import Settings from '../views/Settings.vue'
import Tickets from '../views/Tickets.vue'
import NotFound from '../views/NotFound.vue'
import Devices from '../views/Devices.vue'
import Scenes from '../views/Scenes.vue'

const router = createRouter({
  history: createWebHistory(),
  routes: [
    {
      path: '/',
      name: 'voice',
      component: Voice,
      meta: {
        title: '语音助手'
      }
    },
    {
      path: '/devices',
      name: 'devices',
      component: Devices,
      meta: {
        title: '设备管理'
      }
    },
    {
      path: '/scenes',
      name: 'scenes',
      component: Scenes,
      meta: {
        title: '智能场景'
      }
    },
    {
      path: '/room',
      name: 'room',
      component: Room,
      meta: {
        title: '音乐空间'
      }
    },
    {
      path: '/social',
      name: 'social',
      component: Social,
      meta: {
        title: '社交广场'
      }
    },
    {
      path: '/statistics',
      name: 'statistics',
      component: Statistics,
      meta: {
        title: '使用统计'
      }
    },
    {
      path: '/training',
      name: 'training',
      component: Training,
      meta: {
        title: '语音训练'
      }
    },
    {
      path: '/test',
      name: 'test',
      component: Test,
      meta: {
        title: '音质测试'
      }
    },
    {
      path: '/settings',
      name: 'settings',
      component: Settings,
      meta: {
        title: '系统设置'
      }
    },
    {
      path: '/tickets',
      name: 'tickets',
      component: Tickets,
      meta: {
        title: '问题反馈'
      }
    },
    {
      path: '/:pathMatch(.*)*',
      name: 'notFound',
      component: NotFound,
      meta: {
        title: '页面未找到'
      }
    }
  ]
})

// 更新页面标题
router.beforeEach((to, from, next) => {
  document.title = `${to.meta.title} - AI音箱`
  next()
})

// 路由错误处理
router.onError((error) => {
  console.error('路由错误:', error)
  // 可以添加错误提示或重定向逻辑
})

// 路由切换动画
router.afterEach((to, from) => {
  // 可以在这里添加页面切换动画
  if (document.startViewTransition) {
    document.startViewTransition()
  }
})

export default router 